
package com.be.beadmin.design.repository;

import com.be.beadmin.design.entity.ProductDrawingInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @author zmy
* @date 2023-02-16
**/
public interface ProductDrawingInfoRepository extends JpaRepository<ProductDrawingInfo, String>, JpaSpecificationExecutor<ProductDrawingInfo> {

    ProductDrawingInfo findProductDrawingInfoByIdAndDelete(String id, Integer delete);


    ProductDrawingInfo findProductDrawingInfoByDrawingCodeAndDelete(String drawingCode, Integer delete);
    ProductDrawingInfo findProductDrawingInfoByProductCodeAndDrawingCodeAndCategoryAndDelete(String ProductCode,String drawingCode,String category, Integer delete);
    ProductDrawingInfo findProductDrawingInfoById(String id);


    List<ProductDrawingInfo> findProductDrawingInfosByProductCodeAndDelete(String ProductCode, int delete);



    List<ProductDrawingInfo> findProductDrawingInfosByProductCodeAndPrintFlagAndDelete(String ProductCode,int printFlag, int delete);



    List<ProductDrawingInfo> findProductDrawingInfoByDrawingUrlLikeAndDelete(String drawingName,int delete);

    List<ProductDrawingInfo> findProductDrawingInfosByProductCodeAndCategoryAndDelete(String productCode,String category,int delete);

    List<ProductDrawingInfo> findProductDrawingInfosByProductCodeAndCategoryAndDrawingNameAndDelete(String productCode,String category,String drawingName, int delete);

    ProductDrawingInfo findProductDrawingInfoByIdAndDelete(String productDrawingInfoId, int i);

    int countProductDrawingInfoByProductCodeAndDelete(String productCode,int delete);

    @Query( value = "select count(distinct concat(p.drawing_name, '_', p.category)) from t_om_product_drawing_info p where p.product_code = ?1 and p.is_delete = 0", nativeQuery = true)
    int countNextDrawCode(String productCode);

    List<ProductDrawingInfo> findProductDrawingInfoByProductCodeAndChangeStatusAndDelete(String productCode, int changeStatus, int delete);

//    @Query("select max(convert(p.version, DECIMAL)) from ProductDrawingInfo p where  p.productCode = ?1 and ")

}